//
//  WKSearchHeaderView.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/22.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKSearchHeaderView.h"

@interface WKSearchHeaderView ()
@property(nonatomic,strong)UILabel *titleLb;
@property(nonatomic,strong)UIButton *deteleBtn;
@end

@implementation WKSearchHeaderView



- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
      [self setup];
    }
    return self;
}

- (void)setup{
    
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(12);
        make.size.mas_equalTo(CGSizeMake(200, 20));
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    [self addSubview:self.deteleBtn];
    [self.deteleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-12);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    _deteleBtn.backgroundColor = [UIColor greenColor];
    [_deteleBtn addTarget:self action:@selector(deldeteAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)setIndexPath:(NSIndexPath *)indexPath{
    _indexPath = indexPath;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    _titleLb.text = BLANKSTRING(title);
}

- (void)deldeteAction:(UIButton*)sender{
    if (self.deleteBlock) {
        self.deleteBlock(self.indexPath);
    }
}

- (UILabel*)titleLb{
    if (!_titleLb) {
        _titleLb = [[UILabel alloc]init];
        _titleLb.font = PFSC_MediumFont(12);
        _titleLb.textColor = UIColorFromHex(0x3C3C3C);
    }
    return _titleLb;
}

- (UIButton*)deteleBtn{
    if (!_deteleBtn) {
        _deteleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _deteleBtn;
}

@end
